<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="会议ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="meetingId">
              <j-search-select-tag v-model="model.meetingId" dict="ht_industry_meeting,name,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderId">
              <a-input v-model="model.orderId" placeholder="请输入订单ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报名用户Id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyUserId">
              <a-input v-model="model.applyUserId" placeholder="请输入报名用户Id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="门票数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="quantity">
              <a-input-number v-model="model.quantity" placeholder="请输入门票数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="每人限购数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="limitQuantityPerUser">
              <a-input-number v-model="model.limitQuantityPerUser" placeholder="请输入每人限购数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报名对象：0-展商 1-观众" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyObjectType">
              <j-dict-select-tag type="list" v-model="model.applyObjectType" dictCode="industry_meeting_apply_object_type" placeholder="请选择报名对象：0-展商 1-观众" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="主营产品" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mainProducts">
              <a-input v-model="model.mainProducts" placeholder="请输入主营产品"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="公司类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enterpriseType">
              <a-input v-model="model.enterpriseType" placeholder="请输入公司类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="公司行业" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enterpriseIndustry">
              <a-input v-model="model.enterpriseIndustry" placeholder="请输入公司行业"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="公司名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enterpriseName">
              <a-input v-model="model.enterpriseName" placeholder="请输入公司名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contactPerson">
              <a-input v-model="model.contactPerson" placeholder="请输入联系人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联系手机号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contactPhoneNumber">
              <a-input v-model="model.contactPhoneNumber" placeholder="请输入联系手机号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contactTelephone">
              <a-input v-model="model.contactTelephone" placeholder="请输入联系电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联系人邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contactEmail">
              <a-input v-model="model.contactEmail" placeholder="请输入联系人邮箱"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="联系人职位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contactPosition">
              <a-input v-model="model.contactPosition" placeholder="请输入联系人职位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-textarea v-model="model.remark" rows="4" placeholder="请输入备注" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'HTIndustryMeetingApplyForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           meetingId: [
              { required: true, message: '请输入会议ID!'},
           ],
           applyUserId: [
              { required: true, message: '请输入报名用户Id!'},
           ],
           quantity: [
              { required: true, message: '请输入门票数量!'},
           ],
           applyObjectType: [
              { required: true, message: '请输入报名对象：0-展商 1-观众!'},
           ],
           enterpriseName: [
              { required: true, message: '请输入公司名称!'},
           ],
           contactPerson: [
              { required: true, message: '请输入联系人!'},
           ],
           contactTelephone: [
              { required: true, message: '请输入联系电话!'},
              { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!'},
           ],
           contactEmail: [
              { required: false},
              { pattern: /^([\w]+\.*)([\w]+)@[\w]+\.\w{3}(\.\w{2}|)$/, message: '请输入正确的电子邮件!'},
           ],
        },
        url: {
          add: "/industry/hTIndustryMeetingApply/add",
          edit: "/industry/hTIndustryMeetingApply/edit",
          queryById: "/industry/hTIndustryMeetingApply/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>